package com.gitlab.lucky.eleme.service;

import cn.hutool.http.HttpUtil;
import com.gitlab.lucky.common.dao.mapper.ElemCookieMapper;
import com.gitlab.lucky.common.dao.model.ElemCookie;
import com.gitlab.lucky.common.service.ServiceImpl;
import com.gitlab.lucky.common.weixin.WeixinUtil;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * @program: lucky
 * @author: Mr.Han
 * @create: 2019-03-06 18:07
 **/
@Service
public class ElemCookieService extends ServiceImpl<ElemCookieMapper, ElemCookie> {
    public static void main(String[] args) {
        HashMap objectObjectHashMap = new HashMap<>();
        objectObjectHashMap.put("payjs_order_id","2019042417314800509230053");
        String str = getSign(objectObjectHashMap, "VCCygsQtD2ZqG4mx");
        String body = HttpUtil.createPost("https://payjs.cn/api/refund").form("payjs_order_id", "2019042417314800509230053").form("sign", str).execute().body();

        System.out.println(body);
    }
    public static String getSign(Map map, String PAY_JS_KEY) {
        StringBuffer sb = new StringBuffer();
        Set<String> strings = map.keySet();
        for (String object : strings) {
            Object val = map.get(object);
            sb.append(object);
            sb.append("=");
            sb.append(val);
            sb.append("&");
        }
        sb.append("key=");
        sb.append(PAY_JS_KEY);
        String s = DigestUtils.md5Hex(sb.toString());
        return s.toUpperCase();
    }
}
